﻿using System;

namespace Models
{
    /// <summary>
    /// A database to run a query against
    /// </summary>
    public class Database : ModelBase
    {
        /// <summary>
        /// Full constructor
        /// </summary>
        /// <param name="server">The server that the database is connected to</param>
        /// <param name="database">The name of the database on the server to query</param>
        public Database(Server server, string database)
        {
            DatabaseServer = server;
            DatabaseName = database;
            DatabaseId = Guid.NewGuid();
        }

        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="database">Create a copy of the supplied database</param>
        public Database(Database database)
        {
            DatabaseServer = new Server(database.DatabaseServer);
            DatabaseName = database.DatabaseName;
            DatabaseId = database.DatabaseId;
        }

        /// <summary>
        /// The server on which the database resides
        /// </summary>
        public Server DatabaseServer
        {
            get;
            set;
        }

        /// <summary>
        /// The name of the database on the server to query
        /// </summary>
        public string DatabaseName
        {
            get
            {
                return m_DatabaseName;
            }
            set
            {
                m_DatabaseName = value;
                OnPropertyChanged("DatabaseName");
            }
        }

        /// <summary>
        /// A unique ID given to this database which is used to match result sets and other data this this server
        /// </summary>
        /// <remarks>This value is created when a new instace of this class is created and cannot be altered</remarks>
        public Guid DatabaseId
        {
            get
            {
                return m_DatabaseId;
            }
            private set
            {
                m_DatabaseId = value;
                OnPropertyChanged("DatabaseId");
            }
        }

        /// <summary>
        /// If true then the query will be run against this server
        /// </summary>
        public bool Selected
        {
            get
            {
                return m_Selected;
            }
            set
            {
                m_Selected = value;
                OnPropertyChanged("Selected");
            }
        }

        /// <summary>
        /// The result of running a query against this database
        /// </summary>
        public QueryResult Result
        {
            get
            {
                return m_Result;
            }
            set
            {
                m_Result = value;
                OnPropertyChanged("Result");
            }
        }

        private QueryResult m_Result;
        private bool m_Selected;
        private Guid m_DatabaseId;
        private string m_DatabaseName;
    }
}
